<?php

class Application_Model_User
{
    protected $_id;
    protected $_firstName;
    protected $_lastName;
    protected $_city;
    protected $_phone;
    protected $_comment;

    public function __construct(array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value)
    {
        $method = 'set' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid user property');
        }
        $this->$method($value);
    }

    public function __get($name)
    {
        $method = 'get' . $name;
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid get property');
        }
        return $this->$method();
    }

    public function setOptions(array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }

    public function setId($id)
    {
        $this->_id = (int) $id;
        return $this;
    }

    public function getId()
    {
        return $this->_id;
    }

    public function setFirstName($firstName)
    {
        $this->_firstName = (string) $firstName;
        return $this;
    }

    public function getFirstName()
    {
        return $this->_firstName;
    }

    public function setLastName($lastName)
    {
        $this->_lastName = (string) $lastName;
        return $this;
    }

    public function getLastName()
    {
        return $this->_lastName;
    }

    public function setCity($city)
    {
        $this->_city = (int) $city;
        return $this;
    }

    public function getCity()
    {
        return $this->_city;
    }

    public function setPhone($phone)
    {
        $this->_phone = (array) $phone;
        return $this;
    }

    public function getPhone()
    {
        return $this->_phone;
    }

    public function setComment($comment)
    {
        $this->_comment = (string) $comment;
        return $this;
    }

    public function getComment()
    {
        return $this->_comment;
    }

    public function toArray()
    {
        return array(
            'id'        => $this->_id,
            'firstName' => $this->_firstName,
            'lastName'  => $this->_lastName,
            'city'      => $this->_city,
            'phone'     => $this->_phone,
            'comment'   => $this->_comment,
        );
    }


}

